import 'package:bruno/bruno.dart';
import 'package:common/common.dart';
import 'package:common/image/image_tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../model/register_config.dart';
import '../model/register_config_req.dart';
import 'user_info_edit_info_page.dart';

class UserInfoEditAvaterPage extends StatefulWidget {
  const UserInfoEditAvaterPage({super.key, required this.req, required this.configModel});
  final RegisterConfigReq req;
  final RegisterConfig configModel;

  @override
  State<UserInfoEditAvaterPage> createState() => _UserInfoEditAvaterPageState();
}

class _UserInfoEditAvaterPageState extends State<UserInfoEditAvaterPage> {
  String _filePath = '';

  @override
  Widget build(BuildContext context) {
    Step2? step2 = widget.configModel.step2;

    return Container(
      color: Colors.white,
      child: SafeArea(
        top: false,
        child: Stack(
          children: [
            Image.asset('assets/app/images/auth/background_top_image.png'),
            Scaffold(
                appBar: BrnAppBar(title: '', backgroundColor: Colors.transparent),
                backgroundColor: Colors.transparent,
                body: Padding(
                  padding: EdgeInsets.symmetric(horizontal: 20.w),
                  child: Column(
                    // mainAxisSize: MainAxisSize.max,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(height: 32.h),
                      Padding(
                        padding: EdgeInsets.only(left: 16.0.w),
                        child: Text('选择一张',
                            style: TextStyle(
                                color: const Color(0xFF000000), fontSize: 28.sp, fontWeight: FontWeight.w600)),
                      ),
                      Padding(
                        padding: EdgeInsets.only(left: 16.0.w),
                        child: Text('你最好看的封面照片吧~',
                            style: TextStyle(
                                color: const Color(0xFF000000), fontSize: 24.sp, fontWeight: FontWeight.w500)),
                      ),
                      SizedBox(height: 40.h),
                      GestureDetector(
                        onTap: () {
                          AssetPickerSheet.showBottomSheet(singleCallback: (String filePath) {
                            _filePath = filePath;
                          });
                        },
                        child: Center(
                            child: (step2?.defavatar ?? '').isNotEmpty
                                ? ImageView(url: step2?.defavatar ?? '', width: 135.w)
                                : Image.asset('assets/app/images/user_edit/user_edit_camera.png', width: 135.w)),
                      ),
                      Container(
                          margin: EdgeInsets.only(top: 30.h),
                          alignment: Alignment.center,
                          child: Text(step2?.subtitle ?? '一张真实而有趣的头像会让你更受欢迎哦',
                              style: TextStyle(color: const Color(0xFF111017), fontSize: 13.sp))),
                      SizedBox(height: 40.h),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          _buildSimpleAvaterWarpper(
                              image: step2?.exppics?.left?.uri ?? 'user_edit_avater_1.png',
                              titile: step2?.exppics?.left?.txt ?? '艺术照'),
                          _buildSimpleAvaterWarpper(
                              image: step2?.exppics?.mid?.uri ?? 'user_edit_avater_2.png',
                              titile: step2?.exppics?.mid?.txt ?? '大头贴'),
                          _buildSimpleAvaterWarpper(
                              image: step2?.exppics?.right?.uri ?? 'user_edit_avater_3.png',
                              titile: step2?.exppics?.right?.txt ?? '生活照'),
                        ],
                      ),
                    ],
                  ),
                ),
                bottomNavigationBar: Padding(
                  padding: EdgeInsets.only(left: 20.w, right: 20.w, bottom: Get.bottomBarHeight + 20),
                  child: BrnBigMainButton(
                    title: "下一步 （2/3）".tr,
                    width: double.infinity - 32 * 2,
                    bgColor: const Color(0xFF25D4D0),
                    bgDisEnableColor: const Color(0xFF25D4D0).withOpacity(0.6),
                    themeData: BrnButtonConfig(bigButtonRadius: 255, bigButtonHeight: 45.h, bigButtonFontSize: 16.sp),
                    // isEnable: sex != 0,
                    onTap: () {
                      if (_filePath.isEmpty) {
                        Toast.showText('请设置头像');
                        return;
                      }

                      RegisterConfigReq req = widget.req.copyWith(ifupavatar: 1, filePath: _filePath);
                      Get.to(UserInfoEditInfoPage(req: req, configModel: widget.configModel));
                    },
                  ),
                )),
          ],
        ),
      ),
    );
  }

  Widget _buildSimpleAvaterWarpper({required String image, required String titile}) {
    return Column(
      children: [
        image.startsWith('http')
            ? ImageView(url: image, width: 100.w)
            : Image.asset('assets/app/images/user_edit/$image', width: 100.w),
        const SizedBox(height: 10),
        Text(titile, style: TextStyle(color: const Color(0xFF333333), fontSize: 14.sp))
      ],
    );
  }
}

void show() {}
